const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    line = await readline()
    let [m, n] = line.split(' ').map((i) => parseInt(i)),
        graph = new Array(m).fill(0).map(() => new Array(n).fill(0)),
        visit = new Array(m).fill(0).map(() => new Array(n).fill(false)),
        maxArea = 0;
    // 初始化邻接矩阵
    for (let i = 0; i < m; i++) {
        line = await readline()
        let rowNums = line.split(' ').map((i) => parseInt(i))
        for (let j = 0; j < n; j++) {
            graph[i][j] = rowNums[j]
        }
    }

    for (let i = 0; i < m; i++) {
        for (let j = 0; j < n; j++) {
            if (graph[i][j] === 1 && visit[i][j] === false) {
                visit[i][j] = true
                let sum = 1
                maxArea = Math.max(maxArea, dfs(graph, visit, i, j, sum))
            }
        }
    }
    console.log(maxArea)
}()

function dfs(graph, visit, i, j, sum) {
    let direction = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    for (let [x, y] of direction) {
        let newx = i + x,
            newy = j + y;
        if (newx < 0 || newx >= graph.length || newy < 0 || newy >= graph[0].length) continue
        if (graph[newx][newy] === 1 && visit[newx][newy] === false) {
            visit[newx][newy] = true
            sum = dfs(graph, visit, newx, newy, sum + 1)
        }
    }
    return sum
}



// 广度
void async function () {
    line = await readline()
    let [m, n] = line.split(' ').map((i) => parseInt(i)),
        graph = new Array(m).fill(0).map(() => new Array(n).fill(0)),
        visit = new Array(m).fill(0).map(() => new Array(n).fill(false)),
        maxArea = 0;
    // 初始化邻接矩阵
    for (let i = 0; i < m; i++) {
        line = await readline()
        let rowNums = line.split(' ').map((i) => parseInt(i))
        for (let j = 0; j < n; j++) {
            graph[i][j] = rowNums[j]
        }
    }

    for (let i = 0; i < m; i++) {
        for (let j = 0; j < n; j++) {
            if (graph[i][j] === 1 && visit[i][j] === false) {
                visit[i][j] = true
                let sum = 1
                maxArea = Math.max(maxArea, bfs(graph, visit, i, j, sum))
            }
        }
    }
    console.log(maxArea)
}()

function bfs(graph, visit, i, j, sum) {
    let direction = [[1, 0], [-1, 0], [0, 1], [0, -1]],
        queue = [[i, j]];
    while (queue.length > 0) {
        let [originI, originJ] = queue.pop()
        for (let [x, y] of direction) {
            let newx = originI + x,
                newy = originJ + y;
            if (newx < 0 || newx >= graph.length || newy < 0 || newy >= graph[0].length) continue
            if (graph[newx][newy] === 1 && visit[newx][newy] === false) {
                visit[newx][newy] = true
                sum++
                queue.push([newx, newy])
            }
        }
    }
    return sum
}





/**
 * @param {number[][]} grid
 * @return {number}
 */
var maxAreaOfIsland = function (grid) {
    let maxArea = 0;
    for (let i = 0; i < grid.length; i++) {
        for (let j = 0; j < grid[0].length; j++) {
            if (grid[i][j] === 1) {
                grid[i][j] = 2
                let sum = 1
                maxArea = Math.max(maxArea, dfs(grid, i, j, sum))
            }
        }
    }
    return maxArea;
};

function dfs(grid, i, j, sum) {
    let direction = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    for (let [x, y] of direction) {
        let newx = i + x,
            newy = j + y;
        if (newx < 0 || newx >= grid.length || newy < 0 || newy >= grid[0].length) continue
        if (grid[newx][newy] === 1) {
            grid[newx][newy] = 2
            sum = dfs(grid, newx, newy, sum + 1)
        }
    }
    return sum
}